<?php
include("header.php");

$sections = $_GET["sections"];

$sql = "SELECT 
s.classID AS id,
s.sectionID AS sectionID,
s.sectionNumber AS sectionNumber, 
s.callNumber AS callNumber, 
s.location AS location,
ci.longName AS longName,
ci.numCredits AS credits
FROM sections AS s 
JOIN classes_info AS ci ON ci.classes_classID = s.classID 
WHERE s.sectionID IN ($sections)
";

$r = mysql_query($sql, $con);

$classes = array();
if(mysql_num_rows($r)) {
	while($class = mysql_fetch_assoc($r)) {
	    $classes[] = $class;
	}
}

foreach($classes as &$val){
    $sectionID = $val["sectionID"];
	$sql = "SELECT days.days AS day,
	days.startTime AS startTime,
	days.endTime AS endTime	
	FROM days
	WHERE days.sectionID = $sectionID";
	
	$r = mysql_query($sql, $con);
	$days = array();
	if(mysql_num_rows($r)) {
		while($day = mysql_fetch_assoc($r)) {
			$days[] = $day;
		}
	}
	$val["days"] = $days;
}

header('Content-type: application/json');
echo json_encode($classes);

include("footer.php");
?>
